#include "listeclientmodel.h"

ListeClientModel::ListeClientModel()
{

    QStringList columnHeader;
    columnHeader << "id" << "Nom Lieu" << "Type Client" << "Date Programmation" << "Departement"
                 << "Ville" << "Distance" << "Nom Contact" << "Tel" << "Mail" << "Dernier Contact" << "Prochain Contact";
    setColumnCount(columnHeader.count());
    setHorizontalHeaderLabels(columnHeader);
}
void ListeClientModel::setListeClient(ListeClient liste)
{
    setRowCount(liste.count());

    for (int row = 0; row < liste.count(); row++)
    {

        QStandardItem *itemId = new QStandardItem(QString::number(liste.at(row)->getId()));
        QStandardItem *itemNomLieu = new QStandardItem(liste.at(row)->getNomLieu());
        QStandardItem *itemTypeClient = new QStandardItem(liste.at(row)->getTypeClient());
        QStandardItem *itemDateProgrammation = new QStandardItem(liste.at(row)->getDateProgrammation().toString("MMMM"));
        itemDateProgrammation->setTextAlignment(Qt::AlignCenter);
        if (liste.at(row)->getDateProgrammation().month() == QDate::currentDate().month())
        {
            itemDateProgrammation->setForeground(Qt::red);
        }
        QStandardItem *itemDepartement = new QStandardItem(liste.at(row)->getAdresse().getDepartement());
        itemDepartement->setTextAlignment(Qt::AlignCenter);
        QStandardItem *itemVille = new QStandardItem(liste.at(row)->getAdresse().getVille());
        itemVille->setTextAlignment(Qt::AlignCenter);
        QStandardItem *itemDistance = new QStandardItem(QString::number(liste.at(row)->getDistance()) + " km");
        itemDistance->setTextAlignment(Qt::AlignCenter);

        setItem(row, 0, itemId);
        setItem(row, 1, itemNomLieu);
        setItem(row, 2, itemTypeClient);
        setItem(row, 3, itemDateProgrammation);
        setItem(row, 4, itemDepartement);
        setItem(row, 5, itemVille);
        setItem(row, 6, itemDistance);

        QStandardItem *itemNomContact = new QStandardItem();
        itemNomContact->setTextAlignment(Qt::AlignCenter);
        QStandardItem *itemTelContact = new QStandardItem();
        itemTelContact->setTextAlignment(Qt::AlignCenter);
        QStandardItem *itemMailContact = new QStandardItem();
        itemMailContact->setTextAlignment(Qt::AlignCenter);

        if (liste.at(row)->getListeContact().count() > 0)
        {
            itemNomContact->setText(liste.at(row)->getListeContact().at(0).getNom());
            itemTelContact->setText(liste.at(row)->getListeContact().at(0).getTelephone1WithSpaces());
            itemMailContact->setText(liste.at(row)->getListeContact().at(0).getAdresseMail());
        }
        setItem(row, 7, itemNomContact);
        setItem(row, 8, itemTelContact);
        setItem(row, 9, itemMailContact);

        QStandardItem *itemDernierContact = new QStandardItem(liste.at(row)->getListDateContact().DernierContact().getDate().toString("dd-MM-yyyy"));
        itemDernierContact->setTextAlignment(Qt::AlignCenter);
        if (!liste.at(row)->getListDateContact().DernierContact().getSuccess())
            itemDernierContact->setForeground(Qt::red);
        setItem(row, 10, itemDernierContact);


        QStandardItem *itemProchainContact = new QStandardItem(liste.at(row)->getListDateContact().ProchainContact().toString("dd-MM-yyyy"));
        if (liste.at(row)->getListDateContact().ProchainContact() == QDate::currentDate())
            itemProchainContact->setForeground(Qt::red);
        itemProchainContact->setTextAlignment(Qt::AlignCenter);
        setItem(row, 11, itemProchainContact);
    }
}
bool ListeClientModel::Filtre(QString filtre)
{

}
